using IrisGenerator.Common.Modules;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.DataTypes
{


    public partial class ValueType
    {

        private System.Nullable<System.Guid> _valTypId;

        private string _valTypCode;

        private string _valueTypeDescription;

        private ModuleParameterCollection _moduleParameterCollection;

        private OptionCollection _optionCollection;

        public virtual System.Nullable<System.Guid> ValTypId
        {
            get
            {
                return _valTypId;
            }
            set
            {
                _valTypId = value;
            }
        }

        public virtual string ValTypCode
        {
            get
            {
                return _valTypCode;
            }
            set
            {
                _valTypCode = value;
            }
        }

        public virtual string ValueTypeDescription
        {
            get
            {
                return _valueTypeDescription;
            }
            set
            {
                _valueTypeDescription = value;
            }
        }

        public virtual ModuleParameterCollection ModuleParameterCollection
        {
            get
            {
                if ((this._moduleParameterCollection == null))
                {
                    _moduleParameterCollection = ModuleParameter.Select_MODULE_PARAMETER_By_VAL_TYP_ID(this.ValTypId);
                }
                return this._moduleParameterCollection;
            }
        }

        public virtual OptionCollection OptionCollection
        {
            get
            {
                if ((this._optionCollection == null))
                {
                    _optionCollection = Option.Select_OPTION_By_VAL_TYP_ID(this.ValTypId);
                }
                return this._optionCollection;
            }
        }

        private void Clean()
        {
            this.ValTypId = null;
            this.ValTypCode = string.Empty;
            this.ValueTypeDescription = string.Empty;
            this._moduleParameterCollection = null;
            this._optionCollection = null;
        }

        private void Fill(System.Data.DataRow dr)
        {
            this.Clean();
            if ((dr["VAL_TYP_ID"] != System.DBNull.Value))
            {
                this.ValTypId = ((System.Nullable<System.Guid>)(dr["VAL_TYP_ID"]));
            }
            if ((dr["VAL_TYP_CODE"] != System.DBNull.Value))
            {
                this.ValTypCode = ((string)(dr["VAL_TYP_CODE"]));
            }
            if ((dr["VALUE_TYPE_DESCRIPTION"] != System.DBNull.Value))
            {
                this.ValueTypeDescription = ((string)(dr["VALUE_TYPE_DESCRIPTION"]));
            }
        }

        public static ValueTypeCollection GetAll()
        {
            IrisGenerator.Dal.ValueType dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ValueType();
                System.Data.DataSet ds = dbo.VALUE_TYPE_Select_All();
                ValueTypeCollection collection = new ValueTypeCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        ValueType obj = new ValueType();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static ValueType Load(System.Nullable<System.Guid> VAL_TYP_ID)
        {
            IrisGenerator.Dal.ValueType dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ValueType();
                System.Data.DataSet ds = dbo.VALUE_TYPE_Select_One(VAL_TYP_ID);
                ValueType obj = null;
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        obj = new ValueType();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Load()
        {
            IrisGenerator.Dal.ValueType dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ValueType();
                System.Data.DataSet ds = dbo.VALUE_TYPE_Select_One(this.ValTypId);
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Insert()
        {
            IrisGenerator.Dal.ValueType dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ValueType();
                dbo.VALUE_TYPE_Insert(this.ValTypCode, this.ValueTypeDescription);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Delete()
        {
            IrisGenerator.Dal.ValueType dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ValueType();
                dbo.VALUE_TYPE_Delete(this.ValTypId);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Update()
        {
            IrisGenerator.Dal.ValueType dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ValueType();
                dbo.VALUE_TYPE_Update(this.ValTypId, this.ValTypCode, this.ValueTypeDescription);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }
    }
}
